package com.sairobo.base.modules.sys.manager.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.sairobo.base.common.constant.QueryConts;
import com.sairobo.base.common.entity.Page;
import com.sairobo.base.common.entity.Query;
import com.sairobo.base.modules.sys.dao.SysConfigMapper;
import com.sairobo.base.modules.sys.manager.SysConfigManager;
import com.sairobo.base.modules.sys.entity.SysConfig;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 系统配置信息表
 *
 * @author admin
 * @email sairobo
 * @url www.sairobo.com
 * @date 2018年1月17日 下午7:58:10
 */
@Component("sysConfigManager")
public class SysConfigManagerImpl extends ServiceImpl<SysConfigMapper,SysConfig> implements SysConfigManager {

	@Override
	public List<SysConfig> listSysConfig(Page<SysConfig> page, Query search) {
        EntityWrapper<SysConfig> ew=new EntityWrapper<SysConfig>();
        //搜索条件
        Map map = (HashMap)search.get(QueryConts.SEARCH_KEYWORD);
        String key = (String) map.get("key");
        //ew.like(true,"XXX",(String) map.get("key"));
        //ew.eq(true,"XXX",(String) map.get("key"));

        //if(StringUtils.isNotEmpty(key)){
        //   ew.andNew();
        //   ew.like(true,"nickName",key);
        //   ew.or();
        //   ew.like(true,"province",key);
        //   ew.or();
        //   ew.like(true,"city",key);
        //}

        //and (a like '%keyword%' or b like '%keyword%')
        //ew.andNew();
        //ew.like("a",keyword);
        //ew.or();
        //ew.like("b",keyword);

        ew.orderBy("id",false);
        //ew.orderBy("create_time",false);
        return baseMapper.selectPage(page,ew);
	}

	@Override
	public int saveSysConfig(SysConfig sysConfig) {
        return baseMapper.insert(sysConfig);
	}

	@Override
	public SysConfig getSysConfigById(Long id) {
        SysConfig test = baseMapper.selectById(id);
        return test;
	}

	@Override
	public int updateSysConfig(SysConfig sysConfig) {
        return baseMapper.updateById(sysConfig);
	}

	@Override
	public int batchRemove(Long[] id) {
        int count = baseMapper.deleteBatchIds(Arrays.asList(id));
        return count;
	}

    @Override
    public SysConfig queryByKey(String paramKey) {
        return baseMapper.queryByKey(paramKey);
    }

    @Override
    public int updateValueByKey(String key, String value) {
        return baseMapper.updateValueByKey(key,value);
    }
}
